/*
 * Created by JFormDesigner on Tue Dec 27 15:42:53 ICT 2011
 */

package View;

import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;

import Model.RequestTransferModel;

/**
 * @author Khainx
 */
public class RequestTransferView extends JPanel {
	public RequestTransferView() {
		initComponents();
		readOnly();
		this.btnApproval.setEnabled(false);
		this.btnRefuse.setEnabled(false);
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		label1 = new JLabel();
		scrollPane1 = new JScrollPane();
		tblRequest = new JTable();
		panel1 = new JPanel();
		label2 = new JLabel();
		txtNo = new JTextField();
		label3 = new JLabel();
		txtNumber = new JTextField();
		label4 = new JLabel();
		txtName = new JTextField();
		label5 = new JLabel();
		txtFromLocation = new JTextField();
		label6 = new JLabel();
		txtToLocation = new JTextField();
		label7 = new JLabel();
		txtFromProject = new JTextField();
		label8 = new JLabel();
		txtToProject = new JTextField();
		label9 = new JLabel();
		txtFromDepartment = new JTextField();
		label10 = new JLabel();
		txtToDepartment = new JTextField();
		btnApproval = new JButton();
		btnRefuse = new JButton();
		btnExit = new JButton();

		//======== this ========

		//---- label1 ----
		label1.setText("View Request");
		label1.setFont(new Font("Tahoma", Font.BOLD, 16));

		//======== scrollPane1 ========
		{
			scrollPane1.setViewportView(tblRequest);
		}

		//======== panel1 ========
		{
			panel1.setBorder(new TitledBorder("Request Details"));

			//---- label2 ----
			label2.setText("No.Transfer :");

			//---- label3 ----
			label3.setText("Emp.Number :");

			//---- label4 ----
			label4.setText("Emp.Name :");

			//---- label5 ----
			label5.setText("From Location :");

			//---- label6 ----
			label6.setText("To Location :");

			//---- label7 ----
			label7.setText("From Project :");

			//---- label8 ----
			label8.setText("To Project :");

			//---- label9 ----
			label9.setText("From Department :");

			//---- label10 ----
			label10.setText("To Department :");

			//---- btnApproval ----
			btnApproval.setText("Approval");

			//---- btnRefuse ----
			btnRefuse.setText("Refuse");

			//---- btnExit ----
			btnExit.setText("Exit");

			GroupLayout panel1Layout = new GroupLayout(panel1);
			panel1.setLayout(panel1Layout);
			panel1Layout.setHorizontalGroup(
				panel1Layout.createParallelGroup()
					.addGroup(GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(panel1Layout.createParallelGroup()
							.addGroup(panel1Layout.createSequentialGroup()
								.addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
									.addComponent(label10, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
									.addComponent(label9, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
									.addComponent(label8, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
									.addComponent(label7, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
									.addComponent(label6, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
									.addComponent(label4, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
									.addComponent(label3, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
									.addComponent(label2, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
									.addComponent(label5, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
								.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 98, Short.MAX_VALUE))
							.addGroup(GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
								.addComponent(btnApproval)
								.addGap(28, 28, 28)))
						.addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
							.addGroup(panel1Layout.createSequentialGroup()
								.addComponent(btnRefuse)
								.addGap(35, 35, 35)
								.addComponent(btnExit, GroupLayout.PREFERRED_SIZE, 73, GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 86, Short.MAX_VALUE))
							.addGroup(GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
								.addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
									.addComponent(txtToDepartment)
									.addComponent(txtFromDepartment)
									.addComponent(txtToProject)
									.addComponent(txtFromProject)
									.addComponent(txtToLocation)
									.addComponent(txtFromLocation)
									.addComponent(txtName)
									.addComponent(txtNumber)
									.addComponent(txtNo, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE))
								.addGap(46, 46, 46)))
						.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
			);
			panel1Layout.setVerticalGroup(
				panel1Layout.createParallelGroup()
					.addGroup(panel1Layout.createSequentialGroup()
						.addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
							.addComponent(txtNo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addComponent(label2))
						.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
							.addComponent(label3)
							.addComponent(txtNumber, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
							.addComponent(label4)
							.addComponent(txtName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGap(8, 8, 8)
						.addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
							.addComponent(txtFromLocation, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addComponent(label5))
						.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
							.addComponent(label6)
							.addComponent(txtToLocation, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
							.addComponent(label7)
							.addComponent(txtFromProject, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
							.addComponent(label8)
							.addComponent(txtToProject, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
							.addComponent(label9)
							.addComponent(txtFromDepartment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
							.addComponent(label10)
							.addComponent(txtToDepartment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
							.addComponent(btnExit)
							.addComponent(btnApproval)
							.addComponent(btnRefuse))
						.addContainerGap())
			);
		}

		GroupLayout layout = new GroupLayout(this);
		setLayout(layout);
		layout.setHorizontalGroup(
			layout.createParallelGroup()
				.addGroup(layout.createSequentialGroup()
					.addGroup(layout.createParallelGroup()
						.addGroup(layout.createSequentialGroup()
							.addGap(177, 177, 177)
							.addComponent(label1, GroupLayout.PREFERRED_SIZE, 127, GroupLayout.PREFERRED_SIZE))
						.addGroup(layout.createSequentialGroup()
							.addGap(39, 39, 39)
							.addComponent(panel1, GroupLayout.PREFERRED_SIZE, 524, GroupLayout.PREFERRED_SIZE))
						.addGroup(layout.createSequentialGroup()
							.addContainerGap()
							.addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 765, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		layout.setVerticalGroup(
			layout.createParallelGroup()
				.addGroup(layout.createSequentialGroup()
					.addContainerGap()
					.addComponent(label1)
					.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					.addComponent(scrollPane1, GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
					.addGap(18, 18, 18)
					.addComponent(panel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGap(40, 40, 40))
		);
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}
	public void setModel(TableModel tableModel){
		this.tblRequest.setModel(tableModel);	
	}
	public void setNoTranfer(String string){
		this.txtNo.setText(string);
	}
	public void setNumber(String string){
		this.txtNumber.setText(string);
	}
//	select ID,EmpNumber,EmpName,ToLocation,ToProject,ToDept
	public void setName(String string){
		this.txtName.setText(string);
	}
	public void setToLocation(String string){
		this.txtToLocation.setText(string);
	}
	public void setFromLocation(String string){
		this.txtFromLocation.setText(string);
	}
	public void setToProject(String string){
		this.txtToProject.setText(string);
	}
	public void setFromProject(String string){
		this.txtFromProject.setText(string);
	}
	public void setToDept(String string){
		this.txtToDepartment.setText(string);
	}
	public void setFromDept(String string){
		this.txtFromDepartment.setText(string);
	}
	public void doExit(ActionListener actionListener){
		this.btnExit.addActionListener(actionListener);
	}
	public void doApproval(ActionListener actionListener){
		this.btnApproval.addActionListener(actionListener);
	}
	public void doRefuse(ActionListener actionListener){
		this.btnRefuse.addActionListener(actionListener);
	}
	public int getSelectedItem() {
		return this.tblRequest.getSelectedRow();
	}
	public Object getValueAt(int row,int column){
		return this.tblRequest.getValueAt(row, column);
	}
	public void doSelectTable(MouseAdapter mouseListener) {
		this.tblRequest.addMouseListener(mouseListener);
	}

	public void doSelectTable(KeyAdapter keyListener) {
		this.tblRequest.addKeyListener(keyListener);
	}
	public void clearAll(){
		this.txtNo.setText("");
		this.txtFromDepartment.setText("");
		this.txtFromLocation.setText("");
		this.txtFromProject.setText("");
		this.txtName.setText("");
		this.txtNumber.setText("");
		this.txtToDepartment.setText("");
		this.txtToLocation.setText("");
		this.txtToProject.setText("");
	}
	public void readOnly(){
		this.txtNo.setEditable(false);
		this.txtFromDepartment.setEditable(false);
		this.txtFromLocation.setEditable(false);
		this.txtFromProject.setEditable(false);
		this.txtName.setEditable(false);
		this.txtNumber.setEditable(false);
		this.txtToDepartment.setEditable(false);
		this.txtToLocation.setEditable(false);
		this.txtToProject.setEditable(false);
	}
	public void enable(){
		this.btnApproval.setEnabled(true);
		this.btnRefuse.setEnabled(true);
	}
	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	private JLabel label1;
	private JScrollPane scrollPane1;
	private JTable tblRequest;
	private JPanel panel1;
	private JLabel label2;
	private JTextField txtNo;
	private JLabel label3;
	private JTextField txtNumber;
	private JLabel label4;
	private JTextField txtName;
	private JLabel label5;
	private JTextField txtFromLocation;
	private JLabel label6;
	private JTextField txtToLocation;
	private JLabel label7;
	private JTextField txtFromProject;
	private JLabel label8;
	private JTextField txtToProject;
	private JLabel label9;
	private JTextField txtFromDepartment;
	private JLabel label10;
	private JTextField txtToDepartment;
	private JButton btnApproval;
	private JButton btnRefuse;
	private JButton btnExit;
	// JFormDesigner - End of variables declaration  //GEN-END:variables
}
